package com.mdd.admin.esign;

import com.mdd.admin.esign.comm.EsignHttpHelper;
import com.mdd.admin.esign.comm.EsignHttpResponse;
import com.mdd.admin.esign.enums.EsignRequestType;
import com.mdd.admin.esign.exception.EsignDemoException;

import java.util.Map;

/**
 * description 模板服务
 *
 * @author jzm
 * datetime 2024年1月23日下午14:19:24
 */
public class Template extends Exception {

    private static String eSignHost = EsignDemoConfig.EsignHost;
    private static String eSignAppId = EsignDemoConfig.EsignAppId;
    private static String eSignAppSecret = EsignDemoConfig.EsignAppSecret;

    /**
     * 获取制作合同模板页面
     *
     * @return
     */
    public static EsignHttpResponse getTemplateCreateUrl(String docTemplateName, String fileId) throws EsignDemoException {
        String apiaddr = "/v3/doc-templates/doc-template-create-url";
        //请求参数body体,json格式。get或者delete请求时jsonString传空json:"{}"或者null
//        String jsonParm="{\"docTemplateName\":\"测试模板\",\"docTemplateType\":0,\"fileId\":\"b3f01axxxxxx05d320da35\",\"redirectUrl\":\"https://www.esign.cn\"}";
        String jsonParm = String.format(
                "{\"docTemplateName\":\"%s\",\"docTemplateType\":0,\"fileId\":\"%s\",\"redirectUrl\":\"https://www.esign.cn\"}",
                docTemplateName,
                fileId
        );

        //请求方法
        EsignRequestType requestType = EsignRequestType.POST;
        //生成签名鉴权方式的的header
        Map<String, String> header = EsignHttpHelper.signAndBuildSignAndJsonHeader(eSignAppId, eSignAppSecret, jsonParm, requestType.name(), apiaddr, true);
        //发起接口请求
        return EsignHttpHelper.doCommHttp(eSignHost, apiaddr, requestType, jsonParm, header, true);
    }

}
